﻿using System;
using System.Collections.Generic;
using Soft000.Model;
using Soft000.IDAL;
using Soft000.Data;
using System.Text;
using System.Data;
using System.Data.OleDb;

namespace Soft000.AccessProvider
{
    public class OnLine:Base<OnLineInfo>
    {
        public OnLine()
        {
            TableName = "online";
            KeyField = "id";
        }
        public OnLineInfo GetInfoByIp(string strIp)
        {
            string strSql = "select * from "+TableName+" where o_ip='"+Common.Sql.SqlEncode(strIp)+"'";
            return GetInfoBySql(strSql);
        }
        /// <summary>
        /// 删除超时用户
        /// </summary>
        /// <param name="minute">超时时间</param>
        public void DeleteTimeOut(int minute)
        {
            string strSql = "delete from " + TableName + " where DateDiff('n',o_lasttime,now())>@minute";
            OleDbParameter[] parm ={
                                       new OleDbParameter("@minute",minute)
                                 };
            DbHelper.ExecuteNonQuery(CommandType.Text, strSql, parm);
        }
        /// <summary>
        ///更新用户的最后活动时间
        /// </summary>
        /// <param name="strSystem">操作系统</param>
        /// <param name="strUserName">用户名</param>
        /// <param name="strIp">IP</param>
        public void UpdateLastAction(string strSystem,string strUserName,string strIp)
        {
            string strSql = "update "+TableName+" set o_system=@system,o_username=@username,o_LastTime=now() where o_ip=@ip";
            OleDbParameter[] parm ={
                                       new OleDbParameter("@system",strSystem),
                                       new OleDbParameter("@username",strUserName),
                                       new OleDbParameter("@ip",strIp)
                                 };
            DbHelper.ExecuteNonQuery(strSql);
        }
    }
}
